package com.gaoyi.crm.repository;

import com.gaoyi.crm.db.dao.CategoryDao;
import com.gaoyi.crm.db.entity.Category;
import com.gaoyi.crm.repository.base.BaseRepository;
import com.gaoyi.crm.util.ThreadManager;

import java.util.List;

public class CategoryRepository extends BaseRepository<Category, CategoryDao> {
    @Override
    protected int getIndex() {
        return 1;
    }

    @Override
    protected CategoryDao getDao() {
        return mDatabase.getCategoryDao();
    }


    public void insertCategory(List<Category> categories) {
        mDao.inserts(categories);
    }

    public void insertCategorys(List<Category> categories, TableVersionRepository tableVersionRep) {
        if (categories == null || categories.isEmpty()) {
            return;
        }
        mDao.inserts(categories);
        int ver = 0;
        for (Category bean : categories) {
            if (ver < bean.getSynVer()) {
                ver = bean.getSynVer();
            }
        }
        updateTableVersion(tableVersionRep, ver);
    }
}
